package edu.tomee.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.tomee.db.DatabaseConnection;
import edu.tomee.db.UserInfo;

/**
 * Servlet implementation class SendMsgServlet
 */
@WebServlet("/SendMsgServlet")

public class SendMsgServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public SendMsgServlet() {
        super();
    }
    DatabaseConnection db = new DatabaseConnection();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter pw = response.getWriter();
		String msgbdy = request.getParameter("S1");
		HttpSession session = request.getSession();
		UserInfo userInfo = (UserInfo) session.getAttribute("rslt");
		int uid = userInfo.getUid();
		int status = 0;
		int sender = userInfo.getUid();
		String receiver = request.getParameter("D1"); //can we use D1 in instead uid ?????????
		System.out.println("selected receiver uid is "+receiver);
		int msg_rslt = db.sendmsg(msgbdy,sender,receiver,status);
		request.setAttribute("msg_rslt", msg_rslt);
		request.getRequestDispatcher("msg_report.jsp").forward(request, response);
	}
}
